import dayjs from "dayjs";

var format = (Data: any) => {
    var UserMapping: any = [];
    var DateMapping: any = {};

    for (let i = 0; i < Data.length; i++) {
        const element = Data[i];
        var date = dayjs(element.createTime).format('MM-DD');
        if (!UserMapping.includes(element.nickname)) UserMapping.push(element.nickname);
        if (!DateMapping[date]) {
            DateMapping[date] = {};
            DateMapping[date].users = [];
        };
        DateMapping[date][element.nickname] = element.total || 0;
        DateMapping[date].title = element.title;
        DateMapping[date].description = element.description;
        DateMapping[date].id = element.tid;
        DateMapping[date].users.push({
            nickname: element.nickname,
            total: element.total,
            id: element.id,
            A: element.A,
            B: element.B,
            C: element.C,
            D: element.D,
            E: element.E
        })
    }
    var ChartDate = [];
    for (const key in DateMapping) {
        const element = DateMapping[key];
        ChartDate.push({
            date: key,
            ...element,
        });
    };
    var series = [];
    for (let i = 0; i < UserMapping.length; i++) {
        const element = UserMapping[i];
        series.push({ type: 'line' });
    }
    return {
        UserMapping,
        ChartDate,
        series
    }
}

export {
    format
};